#include <bits/stdc++.h>
#define re register
#define fst first
#define snd second
#define int long long

using namespace std;

typedef pair<int,int> pii;
const int N = 1e6 + 10;
int n,ans;

struct{
    #define son(u,p) (tr[u].ch[p])

    int idx;
    priority_queue<pii,vector<pii>,greater<pii>> q[N];

    struct node{
        int ch[2];
        int dep,cnt;
    }tr[N];

    inline void insert(string s){
        int u = 0;
        for (char c:s){
            int to = c - '0';
            if (!son(u,to)) son(u,to) = ++idx;
            tr[son(u,to)].dep = tr[u].dep + 1;
            u = son(u,to);
        } tr[u].cnt++;
        // cerr << u << " ins\n";
    }

    inline void dfs(int u){
        int tot = (!son(u,0) + !son(u,1));
        // cerr << u << " " << tot << " !!!\n";
        if (son(u,0)) dfs(son(u,0));
        if (son(u,1)) dfs(son(u,1));
        if (!tot){
            int x = son(u,0),y = son(u,1);
            if (q[x].size() < q[y].size()) swap(x,y);
            while (!q[y].empty()){
                q[x].push(q[y].top()); q[y].pop();
            } swap(q[u],q[x]);
        }
        else if (tot == 1){
            if (!q[son(u,0)].empty()) swap(q[u],q[son(u,0)]);
            else swap(q[u],q[son(u,1)]);
            q[u].push({tr[u].dep + 1,0});
        }
        else{
            int t = 0;
            if (tr[u].cnt == 1) q[u].push({tr[u].dep + 2,1});
            else{
                while (1){
                    if ((1ll << t) >= tr[u].cnt){
                        for (re int i = 0;i <= (1ll << (t - 1));i++){
                            if (i + (1ll << (t - 1)) == tr[u].cnt){
                                ans += (i * 2 * t + (tr[u].cnt - i * 2) * (t - 1));
                                for (re int j = 1;j <= i * 2;j++) q[u].push({tr[u].dep + t + 2,1});
                                for (re int j = 1;j <= tr[u].cnt - i * 2;j++) q[u].push({tr[u].dep + t + 1,1});
                                break;
                            }
                        }
                        // ans += (tr[u].cnt * (t - 1)) + (tr[u].cnt - (1ll << (t - 1)));
                        // cerr << u << " " << tr[u].cnt << " " << t << " ???\n";
                        // for (re int i = 1;i <= tr[u].cnt * 2 - (1ll << t);i++) q[u].push({tr[u].dep + t + 2,1});
                        // for (re int i = 1;i <= (1ll << t) - tr[u].cnt;i++) q[u].push({tr[u].dep + t + 1,1});
                        break;
                    } t++;
                }
            } return;
        }
        while (tr[u].cnt--){
            pii t = q[u].top(); q[u].pop();
            ans += (t.fst - tr[u].dep);
            // cerr << u << " " << tr[u].dep << " " << t.fst << " " << t.snd << " ???\n";
            if (!t.snd) q[u].push({t.fst + 2,1});
            else{ q[u].push({t.fst + 1,1}); q[u].push({t.fst + 1,1}); }
        }
    }

    #undef son
}T;

signed main(){
    freopen("id.in","r",stdin);
    freopen("id.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for (re int i = 1;i <= n;i++){
        string s; cin >> s;
        T.insert(s);
    } T.dfs(0);
    cout << ans;
    return 0;
}

/*
no scanf, printf, puts, putchar and so on!!!
*/